﻿@{
    ViewBag.Title = "AdvertiseList";
}

@section scripts
{    
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}

        <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
            <table width="1000px;">
                <tr>
                    <td width="1000px;">
                        <a class="mini-button" id="new" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                        <a class="mini-button" id="add" iconcls="icon-add" onclick="add" plain="true">添加</a>
                        <a class="mini-button" id="modify" iconcls="icon-edit" onclick="modify" plain="true">编辑</a>
                        <a class="mini-button" id="remove" iconcls="icon-remove" onclick="removeRow" plain="true">删除</a>
                        <span class="separator"></span>
                        <a class="mini-button" id="close" iconcls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                    </td>
                </tr>
            </table>
        </div>

                <table>
                    <tr>
                        <td width="100px" align="right">编码或名称: </td>
                        <td width="200px" align="left">
                            <input class="mini-textbox" width="180px" name="key" /></td>
                        <td width="100px" align="left">
                            <a class="mini-button" iconcls="icon-search" onclick="search" plain="true">查询</a></td>
                    </tr>
                </table>
                <div class="mini-fit">
                    <div id="datagrid1" class="mini-datagrid" style="border-style: groove; width: 100%; height: 100%;" pagesize="50"
                        borderstyle="border:1;" url="GetAdvertList"
                        allowcellselect="true" allowcelledit="true" showcolumnsmenu="true" fitcolumns="false"
                        onrowdblclick="modify" sortmode="client">
                        <div property="columns">
                            <div type="checkcolumn" >选行</div>
                            <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                            <div field="ClassName" name="FClassName" width="100" headeralign="center" allowsort="true">广告类型</div>
                            <div field="FNumber" name="FNumber" width="80" headeralign="center" allowsort="true">广告编码</div>
                            <div field="FName" name="FName" width="120" headeralign="center" allowsort="true">广告名称</div>
                            <div field="FImgUrl" name="FImgUrl" width="250" headeralign="center" allowsort="true">广告图URL</div>
                            <div field="FLinkUrl" name="FLinkUrl" width="150" headeralign="center" allowsort="true">广告链接</div>
                            <div field="FSendFlag" name="FSendFlag" width="60" headeralign="center" allowsort="true">是否启用</div>
                            <div field="FOrder" name="FOrder" width="60" headeralign="center" allowsort="true">顺序号</div>
                            <div field="FDate" name="FDate" width="80" headeralign="center" allowsort="true">创建日期</div>
                            <div field="FRemark" name="FRemark" width="100" headeralign="center" allowsort="true">备注</div>
                        </div>
                    </div>
                </div>

<script>
    mini.parse();
    var grid = mini.get("datagrid1");
    function FormShown() {
        LoadListData();
    }

    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'mSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'search':" + "'" + mini.getbyName("key").getValue() + "',";
        json = json + "'type':"+"'1'}]";
        var grid = mini.get("datagrid1");//==
        grid.load({ mjson: json });
    }

    function search() {
        LoadListData();
    }

    //function add() {
    //    var uID = parent.window.getSystemAppID();
    //    mini.open({
    //        url: "/Mall/AdvertiseSet",
    //        title: "广告设置", width: 820, height: 400,
    //        onload: function () {
    //            var iframe = this.getIFrameEl();
    //            var data = { action: "new", FItemID: "0" };
    //            iframe.contentWindow.SetInfoData(data);
    //        },
    //        ondestroy: function (action) {
    //            var grid = mini.get("datagrid1");
    //            grid.reload();
    //        }
    //    });
    //}

    function add() {
        $.post("AddAdvertise", { mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            mini.alert("添加成功");
            grid.reload();
        });
    }

    function removeRow() {
        mini.confirm("确定要删除选中的记录吗？", "提示",
            function (action) {
                if (action == "ok") {
                    remove();
                }
            });
    }

    function remove() {
        
        var row = grid.getSelected();
        if (row) {
            $.post("RemoveAdvertise", { mSystemAppID:parent.window.getSystemAppID(),FItemID: row.FItemID}, function (data) {
                grid.reload();
            });
        }
    }

    function modify() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            if (row.FDataType == "1") {
                mini.open({
                    url: "/Mall/NAVSet",
                    title: "导航设置", width: 880, height: 400,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "edit", FItemID: row.FItemID };
                        iframe.contentWindow.SetInfoData(data);
                    },
                    ondestroy: function (action) {
                        LoadListData();
                    }
                });
            }
            else {
                mini.open({
                    url: "/Mall/AdvertiseSet",
                    title: "广告设置", width: 820, height: 400,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "edit", FItemID: row.FItemID };
                        iframe.contentWindow.SetInfoData(data);
                    },
                    ondestroy: function (action) {
                        LoadListData();
                    }
                });
            }
        } else {
            mini.alert("请选中一条记录");
        }    
    }


</script>